package com.minhua.jijiehao2.mainframe.mine.companyResultActivity.impl

import android.content.Context
import android.content.Intent
import android.text.TextUtils
import android.view.View
import com.minhua.jijiehao2.R
import com.minhua.jijiehao2.base.BaseActivity
import com.minhua.jijiehao2.bean.CompanyIdentifyBean
import com.minhua.jijiehao2.mainframe.circle.companyIdentifyActivity.impl.CompanyIdentifyActivity
import com.minhua.jijiehao2.mainframe.circle.productIdentifyActivity.impl.ProductIdentifyActivity
import com.minhua.jijiehao2.mainframe.mine.companyResultActivity.imp.ICompanyResultView
import kotlinx.android.synthetic.main.activity_company_result.*

class CompanyResultActivity : BaseActivity<ICompanyResultView, CompanyResultPresenter>(), ICompanyResultView {

    override fun getLayoutId(): Int = R.layout.activity_company_result

    override fun getPresenter(): CompanyResultPresenter = CompanyResultPresenter()

    companion object {
        fun intentStart(context: Context, companyIdentifyBean: CompanyIdentifyBean? = null) {
            val intent = Intent(context, CompanyResultActivity::class.java)
            if (companyIdentifyBean != null) {
                intent.putExtra("companyIdentifyBean", companyIdentifyBean)
            }
            context.startActivity(intent)
        }
    }


    override fun initView() {
        val companyIdentifyBean = intent.getSerializableExtra("companyIdentifyBean")
        if (companyIdentifyBean == null) {
            mPresenter.getCompanyResult()
        } else {
            val bean = companyIdentifyBean as CompanyIdentifyBean
            setData(bean)
        }
    }

    private fun setData(bean: CompanyIdentifyBean) {
        tvCompanyName.centerText = bean.companyName
        tvLegalPersonName.centerText = bean.legalPersonName
        tvIDNumber.centerText = bean.idnumber
        tvPhone.centerText = bean.contactTel
        tvLicense.centerText = if (TextUtils.isEmpty(bean.licensePic)) {
            tvLicense.viewHolder.setTextColorRes(R.id.tvContent, R.color.mainRed)
            "未上传"
        } else {
            tvLicense.viewHolder.setTextColorRes(R.id.tvContent, R.color.textColorLevel2)
            "已上传"
        }
        when (bean.auditState) {
            1 -> {
                ivIndicatorFirst.visibility = View.INVISIBLE
                tvStepFirst.setTextColor(resources.getColor(R.color.textColorLevel1))
                ivIndicatorSecond.visibility = View.VISIBLE
                tvStepSecond.setTextColor(resources.getColor(R.color.mainRed))
                ivIndicatorThird.visibility = View.INVISIBLE
                ivStepThird.setImageResource(R.mipmap.indicator31)
                tvStepThird.setTextColor(resources.getColor(R.color.textColorLevel3))
                tvSure.isEnabled = false
                tvSure.text = "提交"
            }
            2 -> {
                ivIndicatorFirst.visibility = View.INVISIBLE
                tvStepFirst.setTextColor(resources.getColor(R.color.textColorLevel1))
                ivIndicatorSecond.visibility = View.INVISIBLE
                tvStepSecond.setTextColor(resources.getColor(R.color.textColorLevel1))
                ivIndicatorThird.visibility = View.VISIBLE
                ivStepThird.setImageResource(R.mipmap.indicator33)
                tvStepThird.setTextColor(resources.getColor(R.color.mainRed))
                tvStepThird.text = "审核通过"
                tvSure.isEnabled = true
                tvSure.text = "产品服务上传"
            }
            3 -> {
                ivIndicatorFirst.visibility = View.INVISIBLE
                tvStepFirst.setTextColor(resources.getColor(R.color.textColorLevel1))
                ivIndicatorSecond.visibility = View.VISIBLE
                tvStepSecond.setTextColor(resources.getColor(R.color.textColorLevel1))
                ivIndicatorThird.visibility = View.INVISIBLE
                ivStepThird.setImageResource(R.mipmap.indicator32)
                tvStepThird.setTextColor(resources.getColor(R.color.mainRedLight))
                tvStepThird.text = "审核未通过"
                tvSure.isEnabled = true
                tvSure.text = "重新提交"
            }
        }

        tvSure.setOnClickListener {
            when (bean.auditState) {
                2 -> startActivity(Intent(this, ProductIdentifyActivity::class.java))
                3 -> startActivity(Intent(this, CompanyIdentifyActivity::class.java))
            }
        }
    }

    override fun onInfoSuccess(companyIdentifyBean: CompanyIdentifyBean) {
        setData(companyIdentifyBean)
    }
}
